//
//  YPRecommendViewController.m
//  ChengHuiTong
//
//  Created by KiVen on 15/11/2.
//  Copyright © 2015年 张文权. All rights reserved.
//

#import "YPRecommendViewController.h"
#import "YPRecommendCell.h"
#import "UIView+Extension.h"
#import "SGFocusImageFrame.h"
#import "SGFocusImageItem.h"
#import "YPWebViewController.h"
#import "LewPopupViewAnimationSlide.h"

#import "CLLockVC.h"

#import "SetPassWordViewController.h"


#import "MarqueeLabel.h"

#import "LewPopupViewAnimationDrop.h"
#import "LewPopupViewController.h"
#import "PopupView.h"
#import "YPInvestDetailViewController.h"


#import "YPInvestDetailModel.h"
#import "RxWebViewController.h"
#import "MainTabbarViewController.h"


#import "NSString+Extension.h"


//下面scrollView之间间隙

#define WIDTH 20

//上面scroll高度

#define ScrollViewHight SCREEN_WIDTH*0.56
//中间投注视图高度
#define MiddleInvestViewHight 220

@interface YPRecommendViewController ()<SGFocusImageFrameDelegate,UIAlertViewDelegate,UITableViewDelegate,UITableViewDataSource>{
    

    NSInteger    _currentPage;
    
    MarqueeLabel*_marqueeLabel;
    
    //轮播图数据源
    NSMutableArray*_SGFocusArr;
    
    //上面的scrollView
    SGFocusImageFrame *_bannerView;

    //label上下间距
    CGFloat interval;
    
    UIView*_MidView;
    
    BOOL _isFirst;
   
    //下面ScrollView数据源
    NSMutableArray *_dataArray;
    
    
    //滚动的Label
    UILabel*_informationLabel;
    
    NSInteger Font;
    
    NSString*_hostUrl;
    
    newUserBid*_newUserBidModel;

    
}
@property (nonatomic,strong)UIView *investView;
@property (nonatomic,strong)UITableView *myTableView;


@end

@implementation YPRecommendViewController

#pragma mark -- lazzy
- (UITableView *)myTableView{
    
    if (!_myTableView) {
        
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49) style:UITableViewStylePlain];
        _myTableView.separatorColor = kColor_cellBorderColor;
        [_myTableView registerClass:[YPRecommendCell class] forCellReuseIdentifier:@"homeCell"];
        _myTableView.delegate = self;
        _myTableView.dataSource = self;
        
        
        //表头
        UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
        headView.backgroundColor = self.view.backgroundColor;
        [headView addSubview:[self creatRecommendView]];
        [headView addSubview:[self creatMidView]];
        headView.height = _MidView.bottom + MiddleInvestViewHight + 30;
        _myTableView.tableHeaderView = headView;
        
        
        UILabel *footLabel = [AppTools getFootLabel];
        [footLabel addLineWithFrame:CGRectMake(0, 0, footLabel.width, 0.5) color:ColorWithRGB(210, 210, 210)];
        _myTableView.tableFooterView = footLabel;
        
        [_myTableView.tableHeaderView addSubview:self.investView];
        
        
        NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"RecomendInvesData"];
        if (dic) {
            [self refreshInvestViewWithModel:[[newUserBid alloc]initWithDic:dic]];
        }
        
    }
    return _myTableView;
}

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    NSLog(@"首页出现");
    [MobClick beginLogPageView:@"推荐首页"];
    
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:YES];
        
    _isFirst=NO;
    
    [MobClick endLogPageView:@"推荐首页"];

}

-(void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    if (!_isFirst) {
        
        [self startRquest];
        
    }
    
    
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getNotice) name:@"AppLaunchRequested" object:nil];
    
    _isFirst=YES;
    
    
    self.automaticallyAdjustsScrollViewInsets=NO;
    
    NSLog(@"%f",SCREEN_HEIGHT);
    
    if (SCREEN_HEIGHT==480) {
        
        interval=5;
        
        Font=12;
        
    }else if (SCREEN_HEIGHT==568){
        
        interval=15;
        
        Font=14;
        
    }else if (SCREEN_HEIGHT==667){
        
        interval=25;
        
        Font=15;
        
    }else{
        
        interval=30;
        
        Font=15;
        
    }
    
    self.view.backgroundColor=kColor_AppBaseBackground;
    
    _dataArray = [[NSMutableArray alloc] init];
    
    _SGFocusArr=[[NSMutableArray alloc] init];
    
    [self judgeGesture];
    
    [self getAllSave];

    [self setUpUI];
    
    [self startURLRequest];

}

- (void)setUpUI{
    
    [self.view addSubview:self.myTableView];
    
}

-(void)getNotice{
    
    NSDictionary*dic=nil;
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"AD_NOTICE"]) {
        
        NSDictionary*noticeDic=[[NSUserDefaults standardUserDefaults] objectForKey:@"AD_NOTICE"];
        
        YPNoticeBin*bin=[[YPNoticeBin alloc] init];
        
        bin.cacheid=noticeDic[@"cacheid"];
        
        dic=[bin dictionaryValue];
        
    }
    [YPHttpRequestMethod sendAsyRequestURL:AD_NOTICE withData:dic withCompletionBlock:^(NSDictionary *responseDictionary) {
        
        NSLog(@"广告%@",responseDictionary);
        
         NSDictionary*noticeDic=[[NSUserDefaults standardUserDefaults] objectForKey:@"AD_NOTICE"];
        
        if ([responseDictionary[@"status"] intValue]==0) {
            
            
            if ([responseDictionary[@"rs_type"]intValue]==0) {
                //没有公告，且客户端需删除缓存
                
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AD_NOTICE"];
                
                [[NSUserDefaults standardUserDefaults] synchronize];
                
            }else if ([responseDictionary[@"rs_type"]intValue]==1){
                //有新公告，且客户端需要重新缓存
                
                [[NSUserDefaults standardUserDefaults] setObject:responseDictionary forKey:@"AD_NOTICE"];
                
                [[NSUserDefaults standardUserDefaults] synchronize];
                
                if ([responseDictionary[@"type"] intValue]==1) {
                    
                    
                    NSString*content;
                    
                    if (responseDictionary[@"content"]) {
                        
                        content=responseDictionary[@"content"];
                        
                    }else{
                        content=noticeDic[@"content"];
                        
                    }
                    
                    [self showNoticeWith:content andShowTime:YES];
                    
                   
                    
                    //只显示一次
                }else if ([responseDictionary[@"type"] intValue]==2){
                    
                    //重复打开应用时显示
                    NSString*content;
                    
                    if (responseDictionary[@"content"]) {
                        
                        content=responseDictionary[@"content"];
                        
                    }else{
                        content=noticeDic[@"content"];
                        
                    }
                    
                     [self showNoticeWith:content andShowTime:YES];
                    
                }else if ([responseDictionary[@"type"] intValue]==3){
                    //始终显示且不能关闭
                    
                    NSString*content;
                    
                    if (responseDictionary[@"content"]) {
                        
                        content=responseDictionary[@"content"];
                        
                    }else{
                        content=noticeDic[@"content"];
                        
                    }
                    
                    [self showNoticeWith:content andShowTime:NO];
                    
                    
                }
                
            }else if ([responseDictionary[@"rs_type"]intValue]==2){
                
                //没有新公告，客户端取本地取缓存即可
                NSDictionary*ADDic=[[NSUserDefaults standardUserDefaults] objectForKey:@"AD_NOTICE"];
                
                if ([ADDic[@"type"] intValue]==1) {
                    
                    
                    
                }else if ([ADDic[@"type"] intValue]==2){
                    
                    
                    [self showNoticeWith:ADDic[@"content"] andShowTime:YES];
                    
                    
                }else if ([ADDic[@"type"] intValue]==3){
                    
                    
                    [self showNoticeWith:ADDic[@"content"] andShowTime:NO];

                }
                
                
            }
            
            
        }
        
    } withFailedBlock:^(NSError *error) {
        
    } withIndicator:NO atView:self.view];
    
}

-(void)startURLRequest{
    

    [RequestModel getBaseUrlSuccessBlock:^(id obj) {

        if ([obj[@"status"] intValue]==0) {
                        
            NSDictionary*dic=obj[@"data"];
            
            NSString*api_url=dic[@"api_url"];
            
            _hostUrl=api_url;
            
            NSLog(@"%@",api_url);

            YPShareAccountInfo*share=[YPShareAccountInfo shareAccountInfo];
   
            share.hostUrl=api_url;
            
            [share saveData];
            
            [self startRquest];
            

        }
        
        
    } failBlock:^(id obj) {
        
        
        if (![YPShareAccountInfo shareAccountInfo].hostUrl) {
            
            [YPShareAccountInfo shareAccountInfo].hostUrl=@"https://www.chenghuitong.net";
            
            [[YPShareAccountInfo shareAccountInfo] saveData];
            
        }
        
        //        [MBProgressHUD showError:@"网络链接失败" toView:self.view];
        
//        [self firstStartGuidance];
        
        
    }];
    
    
}

- (void)judgeGesture{
    
    
    BOOL ison =  [CLLockVC hasPwd];
    
    if(!ison){
        
        NSLog(@"你还没有设置密码，请先设置密码");
        
        
        
    }else {
        
        
        [CLLockVC showVerifyLockVCInVC:self ishome:NO forgetPwdBlock:^{
            
            
        } successBlock:^(CLLockVC *lockVC, NSString *pwd) {
            
            [lockVC dismiss:1.0f];
            
        }];
        
        
    }
    
    
}


#pragma mark - other

#pragma mark--获取缓存

-(void)getAllSave{
    
    NSDictionary*obj=[AppTools getListInfoWithType:Recommend];
    
    
    
    [_dataArray removeAllObjects];
    
    _SGFocusArr=obj[@"picture"];
    
    [self changeHeaderContentWithCustomTable:_SGFocusArr];
    
    
    
    _informationLabel.text=obj[@"notice"][@"content"];
    
    _informationLabel.width=_informationLabel.text.length*15;
    
    
    NSArray*dataArr=obj[@"list"];
    
    for (NSDictionary*dic in dataArr) {
        
        RecommendModel*recommedModel=[[RecommendModel alloc] initWithDic:dic];
        
        [_dataArray addObject:recommedModel];

    }
    
    if (obj) {
        if (_dataArray.count>0) {
            
            //[self creatScrollView];
        }

    }

    
}
#pragma mark 数据请求

- (void)startRquest{
    
    [RequestModel getRecommendDatasuccessBlock:^(id obj) {
        
        NSLog(@"成功%@",obj);
        
        if ([obj[@"status"] intValue]==0) {
            
            [_dataArray removeAllObjects];
            
            _SGFocusArr=obj[@"picture"];
            
            [self changeHeaderContentWithCustomTable:_SGFocusArr];

            _marqueeLabel.text=obj[@"notice"][@"content"];
            
            [_marqueeLabel setLabelize:NO];

            _newUserBidModel=[[newUserBid alloc] initWithDic:obj[@"novice"]];
            
            [self refreshInvestViewWithModel:_newUserBidModel];
           
            for (NSDictionary *dic in obj[@"list"]) {
                
                RecommendModel*recommedModel=[[RecommendModel alloc] initWithDic:dic];
                
                [_dataArray addObject:recommedModel];
            }
            
            
            [self.myTableView reloadData];
            
            [AppTools setListInfo:obj type:Recommend];
            [[NSUserDefaults standardUserDefaults] setObject:[_newUserBidModel dictionaryWithModel] forKey:@"RecomendInvesData"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            
        }
        
        
        
    } failBlock:^(id obj) {
        // [MBProgressHUD hideAllHUDsForView:self.view  animated:YES];
        
        NSLog(@"失败%@",obj);
        
        
    }];
    
}

#pragma mark - 轮播图
- (SGFocusImageFrame *)creatRecommendView{
    
    SGFocusImageItem *item = [[SGFocusImageItem alloc] initWithDict:@{@"image": @"pic_037"} tag:-1];
    
    _bannerView = [[SGFocusImageFrame alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScrollViewHight) delegate:self imageItems:@[item] isAuto:YES isShowTitle:NO isShowCurrentIndex:NO];
    
    _bannerView.timeDurition = 3;
    
    _bannerView.isShowIndex=NO;
    
    _bannerView.delegate = self;
    
    return _bannerView;
    
}

#pragma mark 跑马灯label
-(UIView *)creatMidView{
    
    UITapGestureRecognizer*panGesClick=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(midViewClick)];
    
    
    _MidView=[[UIView alloc] initWithFrame:CGRectMake(0, _bannerView.bottom, SCREEN_WIDTH, 27)];
    _MidView.backgroundColor = [UIColor whiteColor];
    [_MidView addGestureRecognizer:panGesClick];
    
    
    
    
    UIImageView*nameLeft=[[UIImageView alloc] initWithFrame:CGRectMake(autoScaleW(15), 8, 11, 11)];
    nameLeft.image=[UIImage imageNamed:@"home_bg1_"];
    
    _marqueeLabel=[[MarqueeLabel alloc] initWithFrame:CGRectMake(nameLeft.right+5 , 0, SCREEN_WIDTH-nameLeft.right-5 , 27)];
    _marqueeLabel.textColor=UIColorFromString(@"#6c6c6c");
    _marqueeLabel.marqueeType = MLContinuous;
    _marqueeLabel .scrollDuration = 30;
    _marqueeLabel .animationCurve = UIViewAnimationOptionCurveLinear;
    _marqueeLabel .fadeLength = 0;
    _marqueeLabel.leadingBuffer = 30.0f;
    _marqueeLabel.trailingBuffer = 100;
    [_marqueeLabel setLabelize:NO];
    _marqueeLabel.font=[UIFont systemFontOfSize:13];
    
    
    [_MidView addSubview:_marqueeLabel];
    
    [_MidView addSubview:nameLeft];
    
    [_MidView addLine];
    
    return _MidView;
    
}

#pragma mark 投资视图
-(UIView *)investView{
    
    if (!_investView) {
        _investView = [[UIView alloc] initWithFrame:CGRectMake(0, _MidView.bottom + 15, SCREEN_WIDTH, MiddleInvestViewHight)];
        _investView.backgroundColor = [UIColor whiteColor];
        
        UILabel *titie = [[UILabel alloc] initWithFrame:CGRectMake((_investView.width - 17*12 - 10)/2.f, 15, 17*12 + 10, 20)];
        titie.tag = 1000;
        titie.font = [UIFont systemFontOfSize:16];
        titie.textColor = [UIColor blackColor];
        titie.textAlignment = NSTextAlignmentCenter;
        [_investView addSubview:titie];
        
        UILabel *pag=[[UILabel alloc] initWithFrame:CGRectMake((_investView.width - 65)/2.f, titie.bottom + 10, 65, 18)];
        pag.text = @"新手专享";
        pag.textAlignment = NSTextAlignmentCenter;
        pag.font = [UIFont systemFontOfSize:13];
        pag.textColor =kColor_redNumberColor;
        pag.layer.borderColor = kColor_redNumberColor.CGColor;
        pag.layer.borderWidth = 1;
        pag.layer.cornerRadius = pag.height/2.f;
        pag.layer.masksToBounds = YES;
        [_investView addSubview:pag];
        
        
        UILabel *YuQiMoney = [[UILabel alloc] initWithFrame:CGRectMake(0, pag.bottom , _investView.width, 45)];
        YuQiMoney.font=[UIFont systemFontOfSize:15];
        YuQiMoney.textColor=kColor_AppNavColor;
        YuQiMoney.tag = 1001;
        [_investView addSubview:YuQiMoney];
        
        
        UILabel *YuQi = [[UILabel alloc] initWithFrame:CGRectMake(0, YuQiMoney.bottom,_investView.width, 15)];
        YuQi.textAlignment = NSTextAlignmentCenter;
        YuQi.font = [UIFont systemFontOfSize:13];
        YuQi.textColor =  kColor_greyAshTitleColor;
        YuQi.text =@"参考年化收益率";
        [_investView addSubview:YuQi];
        
        
        
        
        UIFont *font = [UIFont systemFontOfSize:13];
        CGFloat margin = 0;
        CGFloat middleW = _investView.width/3.f;
        CGFloat sideW = middleW;
        
        
        UILabel *time = [[UILabel alloc] initWithFrame:CGRectMake(0,YuQi.bottom +10, sideW, 15)];
        time.textColor = _marqueeLabel.textColor;
        time.textAlignment = NSTextAlignmentCenter;
        time.tag = 1002;
        time.font =font;
        [_investView addSubview:time];
        
        
        UILabel *money = [[UILabel alloc] initWithFrame:CGRectMake(time.right + margin * 2, time.top,middleW , time.height)];
        money.textAlignment = NSTextAlignmentCenter;
        money.textColor = time.textColor;
        money.font = time.font;
        money.tag = 1003;
        [_investView addSubview:money];
        
        
        UILabel *ItemMoney = [[UILabel alloc] initWithFrame:CGRectMake(money.right + margin * 2, time.top,sideW , time.height)];
        ItemMoney.textAlignment = NSTextAlignmentCenter;
        ItemMoney.textColor =time.textColor;
        ItemMoney.font = time.font;
        ItemMoney.tag = 1004;
        [_investView addSubview:ItemMoney];
        
        
        [_investView addLineWithFrame:CGRectMake(time.right + margin, time.top+1, 0.5, 13) color:colorWithRGB(220, 220, 220)];
        [_investView addLineWithFrame:CGRectMake(money.right + margin, time.top+1, 0.5, 13) color:colorWithRGB(220, 220, 220)];
        
        
        
        UIButton *buy =[[UIButton alloc] initWithFrame:CGRectMake(autoScaleW(50), time.bottom + 10, _investView.width - autoScaleW(50)*2, 40)];
        buy.layer.cornerRadius = buy.height/2.f;
        buy.layer.masksToBounds = YES;
        
        
        [buy addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [buy setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        buy.titleLabel.font =[UIFont boldSystemFontOfSize:15];
        
        buy.tag = 1005;
        [_investView addSubview:buy];
        
        [_investView addLine];
    }

    return _investView;
    
}

- (void)refreshInvestViewWithModel:(newUserBid *)model{
    
    UILabel *titleLabel = [self.investView viewWithTag:1000];
    UILabel *aprLabel = [self.investView viewWithTag:1001];
    UILabel *timeLabel = [self.investView viewWithTag:1002];
    UILabel *qtLabel = [self.investView viewWithTag:1003];
    UILabel *moneyLabel = [self.investView viewWithTag:1004];
    UIButton *buyBtn = [self.investView viewWithTag:1005];
    
    titleLabel.text = model.title;
    aprLabel.attributedText = [AppTools getAttributedStringWithRate:model.apr
                                                             rateAdd:model.apr_add
                                                            fontSize:30];
    aprLabel.textAlignment = NSTextAlignmentCenter;
    timeLabel.text=[NSString stringWithFormat:@"%@个月",model.time_limit];
    qtLabel.text = [NSString stringWithFormat:@"%@元起投",model.lowest_account];
    moneyLabel.text = [NSString stringWithFormat:@"%@元",model.account];
    
    /**
     2：立即投资
     3：满标复审中
     6：还款中
     7：已完成
     除了“2”，其他值的按钮都是灰色
     
     */
    NSString*titleStr;
    UIColor*buybtnClolors;
    
    if ([model.status intValue]==2) {
        titleStr=@"立即投资";
        buybtnClolors=kColor_AppNavColor;
        //        buy.enabled=YES;
        
    }else if([model.status intValue]==3){
        titleStr=@"满标复审中";
        buybtnClolors=UIColorFromString(@"#969696");
        //        buy.enabled=NO;
        
    }else if([model.status intValue]==6){
        titleStr=@"还款中";
        buybtnClolors=UIColorFromString(@"#969696");
        //        buy.enabled=NO;
        
    }else if([model.status intValue]==7){
        titleStr=@"已完成";
        buybtnClolors=UIColorFromString(@"#969696");
        //        buy.enabled=NO;
        
    }
    buyBtn.backgroundColor =buybtnClolors;
    [buyBtn setTitle:titleStr forState:UIControlStateNormal];
}


#pragma mark--设置轮播图数据源
- (void)changeHeaderContentWithCustomTable: (NSMutableArray *) arr {
    
    
    NSLog(@"%@",arr);
  
     //_bannerView.pageControl.numberOfPages=arr.count;
    
    int length = (int)arr.count;
    
    NSMutableArray *tempArray = [NSMutableArray array];
    
    for (int i = 0 ; i < length; i++)
    {
        
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                              arr[i][@"img_url"],@"image",
                              nil];
        
        [tempArray addObject:dict];
    }
    
    NSMutableArray *itemArray = [NSMutableArray arrayWithCapacity:length+2];
    
    //添加最后一张图 用于循环
    if (length > 1)
    {
        NSDictionary *dict = [tempArray objectAtIndex:length-1];
        
        SGFocusImageItem *item = [[SGFocusImageItem alloc] initWithDict:dict tag:-1] ;
        
        [itemArray addObject:item];
    }
    for (int i = 0; i < length; i++)
    {
        NSDictionary *dict = [tempArray objectAtIndex:i];
        
        SGFocusImageItem *item = [[SGFocusImageItem alloc] initWithDict:dict tag:i] ;
        
        [itemArray addObject:item];
        
    }
    
    //添加第一张图 用于循环
    if (length >1)
    {
        NSDictionary *dict = [tempArray objectAtIndex:0];
        
        SGFocusImageItem *item = [[SGFocusImageItem alloc] initWithDict:dict tag:length] ;
        
        [itemArray addObject:item];
    }
    
    [_bannerView changeImageViewsContent:itemArray];
}

#pragma mark--轮播图点击方法
- (void)foucusIndex:(NSInteger)index didSelectItem:(SGFocusImageItem *)item{
    
    if (!index) {
        
        NSString*url=[NSString stringWithFormat:@"%@",_SGFocusArr[0][@"article_url"]];
        
        if (url.length>0) {

            YPGoWebView(_SGFocusArr[0][@"article_url"], self.navigationController);
        }
    }else{
        NSString*url=[NSString stringWithFormat:@"%@",_SGFocusArr[index-1][@"article_url"]];
        
        if (url.length>0) {

            YPGoWebView(_SGFocusArr[index-1][@"article_url"], self.navigationController);
            
        }

        
    }
    
    
   
    
    
}


#pragma mark MidView点击方法
- (void) midViewClick{
    
    CGSize rect=[_marqueeLabel.text sizeWithFont:[UIFont systemFontOfSize:14] andMaxSize:CGSizeMake((SCREEN_WIDTH*2/3.0)-20, MAXFLOAT)];
    
    rect.height=rect.height+40;
    
    if (rect.height>((SCREEN_HEIGHT/2.0)-30)) {
        
        rect.height=(SCREEN_HEIGHT/2.0)-30;
    }
    
    PopupView*pop=[[PopupView alloc] initWithInformaiton:_marqueeLabel.text withFrame:CGRectMake(0, 0, SCREEN_WIDTH*2/3.0, rect.height+30) isShowButton:YES];
    
    pop.parentVC = self;
    
    pop.dismissView=^{
        
        [self lew_dismissPopupView];
        
    };
    
    [self lew_presentPopupView:pop animation:[LewPopupViewAnimationSpring new] dismissed:^{
        
    }];
    
    
    

    [self lew_presentPopupView:pop animation:[LewPopupViewAnimationSpring new] dismissed:^{
        
    }];
    
    
    
}


-(void)showNoticeWith:(NSString*)notice andShowTime:(BOOL)time{

    if ([APPDelegate.dataDic.allKeys containsObject:@"ad_home"] || [APPDelegate.dataDic.allKeys containsObject:@"update"]) {
        return;
    }
    
    CGSize rect=[notice sizeWithFont:[UIFont systemFontOfSize:14] andMaxSize:CGSizeMake((SCREEN_WIDTH*2/3.0)-20, MAXFLOAT)];
    
    rect.height=rect.height+40;
    
    if (rect.height>((SCREEN_HEIGHT/2.0)-30)) {
        
        rect.height=(SCREEN_HEIGHT/2.0)-30;
    }
    
    PopupView*pop=[[PopupView alloc] initWithInformaiton:notice withFrame:CGRectMake(0, 0, SCREEN_WIDTH*2/3.0, rect.height+30) isShowButton:time];
    
    pop.parentVC = self;
    
   
    
    
    if (time) {
       
        pop.dismissView=^{
            
            [self lew_dismissPopupView];
            
        };
        
        [self lew_presentPopupView:pop animation:[LewPopupViewAnimationSpring new] dismissed:^{
            
        }];
        
       
        
    }else{
        
        [self.tabBarController lew_presentPopupView:pop animation:[LewPopupViewAnimationSpring new] dismissed:^{
            
        }];
    }

}

#pragma mark cell上按钮点击

-(void)cellClick:(UIButton*)sender{
    
    
   
    
    
      
    
   YPInvestDetailViewController*investDetailVC=[[YPInvestDetailViewController alloc] init];
    
    YPInvestModel*model=[[YPInvestModel alloc] init];
    

    
    
     model.bid=_newUserBidModel.bid;
    
    model.title=_newUserBidModel.title;
 
    investDetailVC.investModel=model;
    
    [self.navigationController pushViewController:investDetailVC animated:YES];
    
    
    
}

- (void)actionButton:(UIButton*)actionButton{
    
    RecommendModel*recommendModel=_dataArray[actionButton.tag];
    
    
    YPInvestDetailViewController*investDetailVC=[[YPInvestDetailViewController alloc] init];
    
    YPInvestModel*model=[[YPInvestModel alloc] init];
    
    model.bid=recommendModel.bid;
    
    model.title=recommendModel.title;
    //investDetailVC.investString=recommendModel.title;
    investDetailVC.investModel=model;
    
    [self.navigationController pushViewController:investDetailVC animated:YES];
    
    
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    YPRecommendCell *cell = [tableView dequeueReusableCellWithIdentifier:@"homeCell"];
    
    cell.model = _dataArray[indexPath.row];
    
    cell.selectionStyle = 0;
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 110;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 30;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
    
    UIView *flag = [[UIView alloc]initWithFrame:CGRectMake(autoScaleW(15), 9, 3, 12)];
    flag.backgroundColor = kColor_AppNavColor;
    [headView addSubview:flag];
    
    UILabel *title = [UILabel creatWithFrame:CGRectMake(flag.right + 5, 0, 100, 30)
                                        font:[UIFont systemFontOfSize:13] text:@"精选理财"
                                   textColor:_marqueeLabel.textColor
                               textAlignment:0];
    [headView addSubview:title];
    
    [headView addLine];
    
    return headView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    RecommendModel*recommendModel=_dataArray[indexPath.row];
    
    YPInvestDetailViewController*investDetailVC=[[YPInvestDetailViewController alloc] init];
    YPInvestModel*model=[[YPInvestModel alloc] init];
    model.bid=recommendModel.bid;
    model.title=recommendModel.title;
    investDetailVC.investModel=model;
    [self.navigationController pushViewController:investDetailVC animated:YES];
}


@end
